﻿namespace FFF.Test.Startup
{
    using Abp.AspNetCore;
    using Abp.AspNetCore.Configuration;
    using Abp.AspNetCore.SignalR;
    using Abp.EntityFrameworkCore.Configuration;
    using Abp.Modules;
    using Abp.Reflection.Extensions;
    using FFF.Test.Application.Framework;
    using Microsoft.EntityFrameworkCore;
    using Microsoft.Extensions.Configuration;
    using FFF.Test.DataAccess.Framework;
    using FFF.Test.DataAccess.Framework.Configuration;
    using FFF.Test.Entity;
    using Z.EntityFramework.Extensions;

    /// <summary>
    /// core层模块
    /// </summary>
    [DependsOn(
         typeof(YudmAbpApplication00PubModule),
         typeof(YudmAbpApplication01FWModule),
        typeof(YudmAbpApplication02WXModule),
        typeof(YudmAbpApplication04CFDemoModule),
        typeof(YudmAbpApplication99DemoModule),
        typeof(AbpAspNetCoreModule),
        typeof(AbpAspNetCoreSignalRModule))]
    public class YdmAbpWebModule : AbpModule
    {
        private readonly IConfiguration _appConfiguration;

        /// <summary>
        /// Initializes a new instance of the <see cref="YdmAbpWebModule"/> class.
        /// 应用层构造函数初始化
        /// </summary>
        /// <param name="appConfiguration">程序配置对象</param>
        public YdmAbpWebModule(IConfiguration appConfiguration)
        {
            this._appConfiguration = appConfiguration;
        }

        /// <summary>
        /// 模块初始化之前的调用
        /// </summary>
        public override void PreInitialize()
        {
            // 00Pub
            base.Configuration.Modules.AbpAspNetCore()
           .CreateControllersForAppServices(
               typeof(YudmAbpApplication00PubModule).GetAssembly(),
               useConventionalHttpVerbs: false
           );

            // 01WF
            base.Configuration.Modules.AbpAspNetCore()
           .CreateControllersForAppServices(
               typeof(YudmAbpApplication01FWModule).GetAssembly(),
               useConventionalHttpVerbs: false
           );

            // 02WX
            base.Configuration.Modules.AbpAspNetCore()
           .CreateControllersForAppServices(
               typeof(YudmAbpApplication02WXModule).GetAssembly(),
               useConventionalHttpVerbs: false
           );

            // 04CF
            base.Configuration.Modules.AbpAspNetCore()
              .CreateControllersForAppServices(
                  typeof(YudmAbpApplication04CFDemoModule).GetAssembly(),
                  useConventionalHttpVerbs: false
             );

            // 99demo
            base.Configuration.Modules.AbpAspNetCore()
             .CreateControllersForAppServices(
                 typeof(YudmAbpApplication99DemoModule).GetAssembly(),
                 useConventionalHttpVerbs: false
             );

            // 底层架构
            base.Configuration.Modules.AbpAspNetCore()
              .CreateControllersForAppServices(
                  typeof(YudmAbpApplication99FrameWorkModule).GetAssembly(),
                  useConventionalHttpVerbs: false
              );

            base.Configuration.Auditing.IsEnabled = false;

            // 配置redis
            //base.Configuration.Caching.UseRedis(options =>
            //{
            //    options.ConnectionString = AppConfigConsts.RedisConnectionString;
            //    options.DatabaseId = AppConfigConsts.RedisDatabaseId;
            //});
        }

        /// <summary>
        /// 依赖注入改程序集的类
        /// </summary>
        public override void Initialize()
        {
            this.IocManager.RegisterAssemblyByConvention(typeof(YdmAbpWebModule).GetAssembly());
        }
    }
}
